
from email.mime.text import MIMEText   #邮件的正文
import smtplib,random
def getyzm():
    liststr=[chr(i) for i in range(ord('A'),ord('Z')+1)]+[str(i) for i in range(0,9)]+[chr(i) for i in range(ord('a'),ord('z')+1)]
    yzm=""
    for i in range(6):
        yzm+=random.choice(liststr)
    return yzm
def netmail(receiver):
    user="lwjidea@163.com"
    pwd="lwjidea123"
    sender="lwjidea@163.com"
    receiver=[receiver]
    title = "短租客邮箱验证"
    mail_host = "smtp.163.com"   #163的smtp的服务器
    yzm = getyzm()
    content = "验证码为: "+yzm+"\n如果不是本人操作,请忽略"
    message = MIMEText(content,"plain","utf-8")  #内容，格式，编码
    message["From"] = sender
    message["To"] = ",".join(receiver)
    message["Subject"] = title
    try:
        smtpObj = smtplib.SMTP_SSL(mail_host,465)
        smtpObj.login(user,pwd)
        smtpObj.sendmail(sender,receiver,message.as_string())
        return yzm
    except smtplib.SMTPException  as e:
        print(e)
        return
# print(60*60*24*365*40*100//1000//1000//100)
